#!/usr/bin/python

import sys
import string

filename=sys.argv[1]

ocvtable=[]
fd = open(filename, 'r')
lines = fd.readlines()
fd.close()

length=len(lines)

startmah=float(string.join(lines[0].split()[1].split()))
endmah  =float(string.join(lines[length-1].split()[1].split()))
scale = (endmah-startmah)/100
#startmah=float(lines[0].split()[1].split())
#endmah  =float(lines[length-1].split()[1].split())
print "Start:%fmah"%startmah
print "End  : %fmah"%endmah
print "Scale: %fmah"%scale

index = 0
for i in range(0,101):
	compvalue = scale*i
	while (index < length):
		sample=float(string.join(lines[index].split()[1].split()))
		voltage=float(string.join(lines[index].split()[0].split()))
		if (sample - startmah >= compvalue):
#			print i, lines[index].split()
			ocvtable.append(int(voltage*1000))
			break
		index+=1

ocvtable.sort()
ocvlen=len(ocvtable)
print "OCV Table:"
for y in range(ocvlen/10+1):
	for x in range(0,10):
		if (y*10+x < ocvlen):
			print "%d"%ocvtable[y*10+x],
	print ''

